*******************************************************************************
* Voters
*******************************************************************************

use dataset_voters, clear

keep if year < 2016
gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post
tabulate year, gen(year_)

eststo clear
eststo: areg turnout lnwells year_2 year_3 year_4, a(anid) cl(zipcode)
estadd scalar Nzip = e(N_clust)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout anywells year_2 year_3 year_4, a(anid) cl(zipcode)
estadd scalar Nzip = e(N_clust)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout anyfrackingXpost year_4, a(anid) cl(zipcode)
estadd scalar Nzip = e(N_clust)
estadd local VFE = "Yes"
estadd local YFE = "Yes"

keep if highfracking == 1
eststo: areg turnout lnwells year_2 year_3 year_4, a(anid) cl(zipcode)
estadd scalar Nzip = e(N_clust)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout anywells year_2 year_3 year_4, a(anid) cl(zipcode)
estadd scalar Nzip = e(N_clust)
estadd local VFE = "Yes"
estadd local YFE = "Yes"
eststo: areg turnout anyfrackingXpost year_4, a(anid) cl(zipcode)
estadd scalar Nzip = e(N_clust)
estadd local VFE = "Yes"
estadd local YFE = "Yes"

label variable lnwells "Log wells"
label variable anywells "Any wells"
label variable anyfrackingXpost "Ever fracked X post"

#delimit;

esttab
	using "_output/tableA2a.tex"
	,
		replace
		booktabs
		order(lnwells anywells anyfrackingXpost)
		drop(*year* _cons)
		cells(b(fmt(3) star) se(par))
		compress
		label
		gap
		collabels(none)
		nomtitles
		width(\linewidth)
		mgroups(
			"All states" "High-fracking states", 
			pattern(1 0 0 1 0 0)
			prefix(\multicolumn{@span}{c}{) suffix(})
			span erepeat(\cmidrule(lr){@span})
		)	
		stats(
			YFE
			VFE
			Nzip
			N
			,
				label(
					"Year fixed effects"
					"Voter fixed effects" 
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)
		;
	
#delimit cr

*******************************************************************************
* Donors
*******************************************************************************

use dataset_donors, clear

gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post

drop if mi(ltotamount)
tabulate year, gen(year_)

eststo clear
eststo: areg ltotamount lnwells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
estadd scalar Nzip = e(N_clust)
eststo: areg ltotamount anywells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
estadd scalar Nzip = e(N_clust)
eststo: areg ltotamount anyfrackingXpost year_7, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
estadd scalar Nzip = e(N_clust)

keep if highfracking == 1
eststo: areg ltotamount lnwells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
estadd scalar Nzip = e(N_clust)
eststo: areg ltotamount anywells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
estadd scalar Nzip = e(N_clust)
eststo: areg ltotamount anyfrackingXpost year_7, a(cid) cl(zipcode)
estadd local DFE = "Yes"
estadd local YFE = "Yes"
estadd scalar Nzip = e(N_clust)

label variable lnwells "Log wells"
label variable anywells "Any wells"
label variable anyfrackingXpost "Ever fracked X post"

#delimit;

esttab 
	using "_output/tableA2b.tex"
	,
		replace
		booktabs
		order(lnwells anywells anyfrackingXpost)
		cells(b(fmt(3) star) se(par))
		drop(*year* _cons*)
		compress
		label
		gap
		width(\linewidth)
		collabels(none)
		nomtitles
		mgroups(
			"All states" "High-fracking states", 
				pattern(1 0 0 1 0 0)
				prefix(\multicolumn{@span}{c}{) suffix(})
				span erepeat(\cmidrule(lr){@span})
		)
		stats(
			YFE
			DFE
			Nzip
			N,
				label(
					"Year fixed effects"
					"Donor fixed effects"
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)	
		star(* 0.05 ** 0.01 *** 0.001)
		;
		
#delimit cr

*******************************************************************************
* End
*******************************************************************************
